//
//  MineCollectViewController.m
//  ArtDog
//
//  Created by dllo on 16/9/14.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "MineCollectViewController.h"
#import "BaseCollectionView.h"
#import "HeadLabelsView.h"
#import "HLMacro.h"
#import "UIColor+Common.h"
#import "MineCollectMainCollectionCell.h"

@interface MineCollectViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) BaseCollectionView *collectionView;

@property (nonatomic, strong) HeadLabelsView *titleView;

@end

@implementation MineCollectViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNavigationBar];
    [self createCollectionView];
}
- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setupNavigationBar
{
    UIView *topLineView = [[UIView alloc]initWithFrame:CGRectMake(0, 63, SCREEN_WIDTH, 1)];
    [self.view addSubview:topLineView];
    topLineView.backgroundColor = [UIColor colorFromHexRGB:@"dddddd"];
    UIView *bottomLineView = [[UIView alloc]initWithFrame:CGRectMake(0, 107, SCREEN_WIDTH, 1)];
    [self.view addSubview:bottomLineView];
    bottomLineView.backgroundColor = [UIColor colorFromHexRGB:@"eeeeee"];
    _titleView = [[HeadLabelsView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 44)];
    _titleView.titles = @[@"图文", @"专题", @"图片", @"展览", @"作品", @"商品"];
    [self.view addSubview:_titleView];
    __weak typeof(self) weakSelf = self;
    _titleView.collectionViewOffset = ^(CGFloat collectionViewOffset) {
        [weakSelf.collectionView setContentOffset:CGPointMake(collectionViewOffset, 0) animated:YES];
    };
    
}

- (void)createCollectionView
{
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    _collectionView = [[BaseCollectionView alloc]initWithFrame:CGRectMake(0, 64 + 44, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 44) collectionViewLayout:flowLayout];
    [self.view addSubview:_collectionView];
    flowLayout.itemSize = _collectionView.frame.size;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 0;
    flowLayout.minimumInteritemSpacing = 0;
    
    _collectionView.pagingEnabled = YES;
    _collectionView.bounces = NO;
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.showsHorizontalScrollIndicator = NO;
    
    [_collectionView registerNib:[UINib nibWithNibName:@"MineCollectMainCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"mineCollectMainCollectionCell"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MineCollectMainCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"mineCollectMainCollectionCell" forIndexPath:indexPath];
    cell.type = indexPath.item;
    
    return cell;
}

#pragma mark - scrollView delegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    _titleView.collectionViewOffset = nil;
    [_titleView setButtonSelect:scrollView.contentOffset.x / SCREEN_WIDTH];
    __weak typeof(self) weakSelf = self;
    _titleView.collectionViewOffset = ^(CGFloat collectionViewOffset) {
        [weakSelf.collectionView setContentOffset:CGPointMake(collectionViewOffset, 0) animated:YES];
    };
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
